package com.yicong.ants.ui.present;

import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.cchao.simplelib.ui.activity.BaseTitleBarActivity;
import com.google.gson.Gson;
import com.yicong.ants.R;
import com.yicong.ants.bean.task.TaskInfo;
import com.yicong.ants.databinding.ActivityDoingTaskBinding;
import com.yicong.ants.databinding.TaskPager2ItemBinding;
import com.yicong.ants.manager.AppHelper;

import java.util.List;


public class DoingTaskActivity extends BaseTitleBarActivity<ActivityDoingTaskBinding> implements View.OnClickListener {

    @Override
    protected int getLayout() {
        return R.layout.activity_doing_task;
    }

    private TaskInfo mBean;

    @Override
    protected void initEventAndData() {
        setTitleBarVisible(false);
        AppHelper.transStatus(getWindow());
        mDataBind.title.setText("门票进行中任务");
        mDataBind.setClick(this);
        String data = getIntent().getStringExtra("TaskInfo");
        mBean = new Gson().fromJson(data, TaskInfo.class);
        updatePage();
    }

    @Override
    protected void onLoadData() {

    }

    void updatePage() {
        mDataBind.fhTip.setText("门票剩余待返还");
        mDataBind.fhNumber.setText(mBean.getRemain_return());

        mDataBind.content.removeAllViews();
        List<TaskInfo.IngBean> list = mBean.getTask_ing();
        if (list == null || list.size() == 0) {
            mDataBind.emptyView.setVisibility(View.VISIBLE);
            return;
        }
        mDataBind.emptyView.setVisibility(View.GONE);

        for (int i = 0; i < list.size(); i++) {
            TaskPager2ItemBinding binding = DataBindingUtil.inflate(mLayoutInflater, R.layout.task_pager2_item, null, false);
            binding.setUnit("门票");
            binding.setDay("天");
            binding.setBean(list.get(i));
            mDataBind.content.addView(binding.getRoot());
        }
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.back) {
            finish();
        } else if (id == R.id.exchangeBtn) {
            finish();
        }
    }
}
